package cn.kgc.javaweb.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author: mosin
 * @version: v1.0  2022/5/26
 */
@WebServlet("/session")
public class SessionServlet extends  BaseServlet {


    protected void test(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*
        *客户端第一次请求时 服务端会创建一个session对象  同时创建一个cookie对象
        * 并且把session对象的id 作为cookie的value  进行存储响应给客户端
        * cookie是生成在服务端 保存咋客户端的一个缓存文件
        * */
        HttpSession session = req.getSession();
        String id = session.getId();
        System.out.println("sessionId = " + id);
        resp.sendRedirect("index.jsp");
    }

}
